package com.pachong.android.framework.httprequest;


import android.content.Context;
import android.util.Log;

import com.pachong.android.framework.BuildConfig;
import com.pachong.android.framework.httprequest.responsecallbacks.RequestListener;
import com.pachong.android.framework.httprequest.volleyadaptee.VolleyHttp;

import org.json.JSONObject;

import java.util.Map;


public class HttpRequest implements IHttpRequest {

    public static final String TAG = HttpRequest.class.getSimpleName();
    private final static boolean DEBUG = BuildConfig.DEBUG;

    private IHttpRequest mAdaptee = null;


    public HttpRequest(Context context) {
        mAdaptee = new VolleyHttp(context);
    }

    @Override
    public void get(String url, UrlParams params, RequestListener cb) {
        mAdaptee.get(url, params, cb);
    }

    @Override
    public void get(String url, UrlParams params, Map<String, String> headParams, RequestListener cb) {
        mAdaptee.get(url, params, headParams, cb);
    }


    @Override
    public void put(String url, JSONObject jsonObject, RequestListener cb) {
        mAdaptee.put(url, jsonObject, cb);
    }

    @Override
    public void put(String url, JSONObject jsonObject, Map<String, String> headParams, RequestListener cb) {
        mAdaptee.put(url, jsonObject, headParams, cb);
    }


    @Override
    public void post(String url, UrlParams params, final RequestListener cb) {
        mAdaptee.post(url, params, cb);

    }

    @Override
    public void post(String url, UrlParams params, Map<String, String> headParams, RequestListener cb) {
        mAdaptee.post(url, params, headParams, cb);
    }

    @Override
    public void post(String url, JSONObject jsonObject, final RequestListener cb) {
        mAdaptee.post(url, jsonObject, cb);
    }

    @Override
    public void post(String url, JSONObject jsonObject, Map<String, String> headParams, RequestListener cb) {
        mAdaptee.post(url, jsonObject, headParams, cb);
    }

    @Override
    public void delete(String url, UrlParams params, RequestListener cb) {
        mAdaptee.delete(url, params, cb);
    }

    @Override
    public void delete(String url, UrlParams params, Map<String, String> headParams, RequestListener cb) {
        mAdaptee.delete(url, params, headParams, cb);
    }

    @Override
    public void finish() {
        mAdaptee.finish();
    }

    public static void log(String msg) {
        if (DEBUG) {
            Log.d(TAG, msg);
        }
    }


}
